<?php

namespace App\Http\Middleware;

use Closure;

class WxAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        $openid = $request->header('x-wx-openid', null);
        if (!$openid) {
            return response()->json(['code' => 401, 'msg' => '请先登录']);
        }
        $request->attributes->add([
            'openid' => $openid,
            'token' => $request->header('x-wx-cloudbase-access-token', null),
            'unionid' => $request->header('x-wx-unionid', null),
            'appid' => $request->header('x-wx-appid', ""),
        ]);
        return $next($request);
    }
}
